package com.maserb.monitor.remote;

import com.maserb.monitor.dataCenter.communication.MonitorMessageProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class AFSTMessageEncoder extends MessageToByteEncoder<AFSTMessageProtocol> {

    @Override
    protected void encode(ChannelHandlerContext tcx, AFSTMessageProtocol msg,
                          ByteBuf out) throws Exception {
        byte[] lengthData = MessageByteUtils.fromString(msg.getCommmandLength().toString(), 4);
        out.writeBytes(lengthData);
        byte[] funNo = MessageByteUtils.fromString(msg.getFuncNo(), 2);
        out.writeBytes(funNo);
        byte[] seqNo = MessageByteUtils.fromString(msg.getSeqNo().toString(), 4);
        out.writeBytes(seqNo);

        out.writeBytes(msg.getContent());
    }
}